package com.ruoyi.web.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Video;
import com.ruoyi.system.service.IVideoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 视频管理Controller
 *
 * @author ruoyi
 * @date 2022-07-26
 */
@Controller
@RequestMapping("/system/video")
public class VideoController extends BaseController {
    private String prefix = "system/video";

    @Autowired
    private IVideoService videoService;

    @RequiresPermissions("system:video:view")
    @GetMapping()
    public String video() {
        return prefix + "/video";
    }

    /**
     * 查询视频管理列表
     */
    @RequiresPermissions("system:video:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Video video) {
        startPage();
        List<Video> list = videoService.selectVideoList(video);
        return getDataTable(list);
    }

    /**
     * 导出视频管理列表
     */
    @RequiresPermissions("system:video:export")
    @Log(title = "视频管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Video video) {
        List<Video> list = videoService.selectVideoList(video);
        ExcelUtil<Video> util = new ExcelUtil<Video>(Video.class);
        return util.exportExcel(list, "视频管理数据");
    }

    /**
     * 新增视频管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存视频管理
     */
    @RequiresPermissions("system:video:add")
    @Log(title = "视频管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Video video) {
        return toAjax(videoService.insertVideo(video));
    }

    /**
     * 修改视频管理
     */
    @RequiresPermissions("system:video:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Video video = videoService.selectVideoById(id);
        mmap.put("video", video);
        return prefix + "/edit";
    }

    /**
     * 修改保存视频管理
     */
    @RequiresPermissions("system:video:edit")
    @Log(title = "视频管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Video video) {
        return toAjax(videoService.updateVideo(video));
    }

    /**
     * 删除视频管理
     */
    @RequiresPermissions("system:video:remove")
    @Log(title = "视频管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(videoService.deleteVideoByIds(ids));
    }


    /**
     * 新增视频
     *
     * @param video
     * @return
     */
    @PostMapping("/myadd")
    @ResponseBody
    public AjaxResult myadd(Video video) {
        return toAjax(videoService.insertVideo(video));
    }

    /**
     * 删除视频
     *
     * @param id
     * @return
     */
    @PostMapping("/myremove")
    @ResponseBody
    public AjaxResult myremove(@RequestParam("id") Long id) {
        return toAjax(videoService.deleteVideoById(id));
    }

    /**
     * 获得视频列表
     *
     * @param video
     * @return
     */
    @PostMapping("/mylist")
    @ResponseBody
    public AjaxResult myGetList(Video video) {
        return success(videoService.selectVideoList(video));
    }
}
